<template>
  <view class="home-banner">
    <view class="home-banner__main">
      <view class="home-banner__item" @click="handleOrderClick">
        <view class="home-banner__item-title">
          <text class="home-banner__item-title-icon is-order"></text>
          <text class="home-banner__item-title-text">{{ translate('home_banner_order_title') }}</text>
        </view>
        <view class="home-banner__item-description">{{ translate('home_banner_order_desc') }}</view>
      </view>
      <view class="home-banner__item" @click="handleOrderMemoClick">
        <view class="home-banner__item-title">
          <text class="home-banner__item-title-icon is-finance"></text>
          <text class="home-banner__item-title-text">{{ translate('home_banner_finance_title') }}</text>
        </view>
        <view class="home-banner__item-description">{{ translate('home_banner_finance_desc') }}</view>
      </view>
      <view class="home-banner__item" @click="handleOrderDeliveryClick">
        <view class="home-banner__item-title">
          <text class="home-banner__item-title-icon is-delivery"></text>
          <text class="home-banner__item-title-text">{{ translate('home_banner_delivery_title') }}</text>
        </view>
        <view class="home-banner__item-description">{{ translate('home_banner_delivery_desc') }}</view>
      </view>
    </view>
  </view>
</template>

<script>
import BiOrderMemoBadge from '@/common/order-memo-badge/order-memo-badge.vue'
import { buildUrl } from '@/utils/url'
import { success, error } from '@/utils/message.js'

// 导入语言文件
import zhLang from '@/utils/zh.js';
import enLang from '@/utils/en.js';
import storage from "@huntianning/miniprogram/utils/storage.js";

export default {
  name: 'HomeBanner',
  components: {
    BiOrderMemoBadge
  },
  data() {
    return {
      currentLocale: 'zh', // 默认语言
      // 语言包
      languages: {
        'zh': zhLang,
        'en': enLang
      }
    }
  },
  mounted() {
    // 初始化语言
    let savedLanguage = uni.getStorageSync('language') || 'zh';
    const currentTimeType = storage.get('CURRENT_TIME_TYPE');
    savedLanguage=(currentTimeType === 1 || currentTimeType === '1') ? 'en' : 'zh';
    this.currentLocale = savedLanguage;
  },
  methods: {
    // 翻译函数 - 与 order-delivery 页面保持一致
    translate(key) {
      try {
        const langPack = this.languages[this.currentLocale] || this.languages['zh'];
        return langPack[key] || key;
      } catch (e) {
        console.error('Translation error:', e);
        return key;
      }
    },

    handleOrderClick () {
      uni.navigateTo({
        url: '/packages/mine/order/order-create'
      })
    },
    handleOrderMemoClick () {
      uni.navigateTo({
        url: '/packages/mine/order/order-create-finance'
      })
    },
    handleOrderDeliveryClick () {
      uni.navigateTo({
        url: '/packages/mine/order/order-delivery/order-delivery-create'
      })
    },
    reload () {
      this.$refs.memoBadge && this.$refs.memoBadge.reload()
    }
  }
}
</script>

<style lang="less">
.home-banner{
  padding: 0 10rpx;
  position: relative;
  &:after {
    content: '';
    display: block;
    height: 30rpx;
  }
  &:before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 50rpx;
    background-color: #EABC30;
  }
  .is-hight{
    color: #F47554;
  }
}
.home-banner__main{
  background-color: #fff;
  border-radius: 12rpx;
  box-shadow: 0px 3px 4px -1px #DCE2E8;
  padding: 15rpx 0;
  display: flex;
  flex-direction: row;
  position: relative;
  bottom: -40rpx;
  z-index: 3;
  height: 135rpx;
  padding-top: 10rpx;
  position: relative;
}
.home-banner__item{
  flex: 1;
  min-width: 0;
  padding: 15rpx 15rpx;
  position: relative;
  &:not(:first-child) {
    &:after {
      content: '';
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
      width: 1px;
      background-color: #E3E5E5;
    }
  }
}
.home-banner__item-title{
  height: 30px;
  line-height: 30px;
  display: flex;
  flex-direction: row;
  align-items: center;
}
.home-banner__item-title-icon{
  display: inline-block;
  width: 40rpx;
  height: 40rpx;
  border-radius: 5rpx;
  margin-right: 10rpx;
  background-position: 50% 50%;
  background-size: 40rpx;
  background-repeat: no-repeat;
  &.is-order {
    background-image: url('./images/order1.png');
  }
  &.is-finance {
    background-image: url('./images/finance.png');
  }
  &.is-delivery {
    background-image: url('./images/delivery.png');
  }
}
.home-banner__item-title-text{
  font-size: 24rpx;
  font-weight: 900;
}
.home-banner__item-description{
  font-size: 22rpx;
  text-align: center;
  color: #666666;
  height: 40rpx;
  line-height: 40rpx;
  white-space: nowrap;
}
.home-banner__item-title-badge{
  margin-left: 5px;
}
</style>
